﻿@model List<Century.Model.CMS.Site>
@if (Model != null && Model.Count > 0)
{
    <a class="languageMainLink" href="#">
        <img src="/content/themes/default/img/general/flags/@(Century.Web.UI.MVC.FrameworkToken.UserToken.CurrentSite.Flag)" alt="En" class="languageFlag" />
        <span class="languageSpan">@(
 Model.Any(c => c.Id == Century.Web.UI.MVC.FrameworkToken.UserToken.CurrentSite.Id) ?
        Model.First(c => c.Id == Century.Web.UI.MVC.FrameworkToken.UserToken.CurrentSite.Id).Name :
        Model.First().Name)</span>
        <img src="/content/themes/default/img/header/languageBoxIcon.png" alt="" class="languageBoxArrow" />
    </a>

    <div class="languageBoxMenuDiv" style="display: none;">
        <ul>
            @foreach (Century.Model.CMS.Site item in Model)
            {
                <li><a title="@item.Name" href="#" onclick="onCountryListChange(@item.Id);">
                    <div>
                        <img src="/content/themes/default/img/general/flags/@item.Flag" alt="@item.Flag"><span>@item.Name</span>
                    </div>
                </a></li>
            }
        </ul>
    </div>
            using (Html.BeginScripts())
            {
    <script type="text/javascript">
        function onCountryListChange(id) {
            $.ajax({
                type: "post",
                url: '@Url.Action("CountrySiteChange", "SiteSelector", new { area = "Admin" })',
                    data: {
                        selectedCountrySiteId: id
                    },
                    dataType: "text",
                    success: function (msg) {
                        document.location.reload();
                    },
                    error: function (msg) {
                        alert('Error on changing country site');
                    }
                });
            }
    </script>
            }
}
else
{
    <text>There is no available site.</text>
}